home *** CD-ROM | disk | FTP | other *** search
- /*
- Rotating Rects
-
- This application will draw rectangles within the bounds the window. The rectangles will be rotated, scaled, and
- colored with an HSV color. All of the functions in this file are called by the graphics shell.
-
- NOTES:
- • This file requires the following files to run correctly:
- "graphics shell.c", "GraphicsDebugLibrary.c", and "TransformLibrary.c".
-
- • For the best printing results, print this file in "landscape".
-
- Change History:
-
- 4/96 bob Updated #includes to support changed GX Library names.
- Changed fixed to Fixed.
- Updated the note regarding the files needed to run.
- Updated the copyright date.
-
- ©1990 - 1996 Apple Computer, Inc.
- All rights reserved.
- */
-
-
- #include <Events.h>
- #include <Windows.h>
-
- #include "GraphicsLibraries.h"
- #include <GXEnvironment.h>
- #include "graphics shell.h"
-
- #define f(a,b) (((Fixed) (a) << 16) + (b))
- #define kNumberOfRectanglesDrawn 110
-
- //
- // Set up the title and size of the window
- //
- Str255 gWindowTitle = "\p Rotating Rects (dither level = 4)";
- Rect gWindowQDRect = {50, 50, 330, 330};
-
- //
- // gGraphicsHeapSize sets the size of the graphics gxHeap created by calling the GXNewGraphicsClient routine
- // in main () within graphics shell.c. You can determine the amount of graphics gxHeap required by using GraphicsBug.
- // With gGraphicsHeapSize set to 25k, I had 3 free blocks left in the graphics gxHeap. Sounds good to me.
- //
- long gGraphicsHeapSize = 25;
-
- gxShape gRectangleShape;
- gxRectangle gFixedWindowBounds; /** bounding box of the window in local coordinates **/
- gxColor gRectangleColor;
- Boolean gChangeShapeFill;
- short gTotalnumberOfRectanglesDrawn;
-
-
- /*------ DoInitialization ---------------------------------------------------------------------------------*/
-
- void DoInitialization(aWindow)
- WindowPtr aWindow;
- {
- gxViewPort windowViewPortParent;
-
- gChangeShapeFill = true;
- gTotalnumberOfRectanglesDrawn = 0;
-
- //
- // Get the viewPort that is attached to the window, and set the dither of this viewPort to 4. Which
- // will mean that all objects that are drawn into window will be dithered at a dither level of 4.
- //
- windowViewPortParent = GXGetWindowViewPort(aWindow);
- GXSetViewPortDither(windowViewPortParent, 4);
-
- //
- // Get the bounds of the window, and create a gxRectangle that will fill the window
- //
- GXGetShapeBounds(gWindowBoundsShape, 0L, &gFixedWindowBounds);
- gRectangleShape = GXNewRectangle(&gFixedWindowBounds);
-
- //
- // Set up an HSV gxColor space to run the rectangles through...
- //
- gRectangleColor.space = gxHSVSpace;
- gRectangleColor.profile = nil;
- gRectangleColor.element.hsv.hue = 0x0000;
- gRectangleColor.element.hsv.value = 0xFFFF;
- gRectangleColor.element.hsv.saturation = 0xFFFF;
- }
-
-
- /*------ DoDraw ---------------------------------------------------------------------------------------*/
-
- void DoDraw(aWindow)
- WindowPtr aWindow;
- {
- gxRectangle rectangleBoundsShape;
- Fixed x, y;
-
- if (gTotalnumberOfRectanglesDrawn == kNumberOfRectanglesDrawn) {
-
- //
- // Time to rebuild the gxRectangle... Dispose of the "old" rectangle, and re-create a rectangle that will fill the window
- //
- GXDisposeShape(gRectangleShape);
- gRectangleShape = GXNewRectangle(&gFixedWindowBounds);
-
- //
- // Set the gxShapeFill type, alternate drawing the gxRectangle with a solid fill and a gxClosedFrameFill
- //
- if (gChangeShapeFill == true) {
- SetPort (aWindow);
- EraseRect(&(aWindow)->portRect);
- GXSetShapeFill (gRectangleShape, gxClosedFrameFill);
- gChangeShapeFill = false;
- }
- else gChangeShapeFill = true;
-
- gTotalnumberOfRectanglesDrawn = 0;
- }
-
- GXSetShapeColor(gRectangleShape, &gRectangleColor);
- GXDrawShape(gRectangleShape);
-
- gRectangleColor.element.hsv.hue += 0x0300;
-
- //
- // Get the new bounds of the rectangle after it has been scaled by calling GXScaleShape. Each call to GXScaleShape
- // changes the bounding shape (box) of the rectangle. Determine the center of the bounding box, pass the center
- // to the GXRotateShape call. This will have the rectagnel rotated about the center.
- //
- GXGetShapeBounds(gRectangleShape, 0L, &rectangleBoundsShape);
- x = rectangleBoundsShape.left + rectangleBoundsShape.right >> 1;
- y = rectangleBoundsShape.top + rectangleBoundsShape.bottom >> 1;
-
- GXRotateShape(gRectangleShape, ff(2), x, y);
- GXScaleShape(gRectangleShape, f(0, 0xF800), f(0, 0xF800), x, y);
-
- gTotalnumberOfRectanglesDrawn++;
- }
-
-
- /*------ DoDispose -------------------------------------------------------------------------------------*/
-
- void DoDispose(aWindow)
- WindowPtr aWindow;
- {
- //
- // You should always dispose of your GX graphics objects before tossing your window. Why? It's generally good
- // form and this approach guarantees that everything is disposed. If you had not disposed of everything, the
- // call to DisposeWindow should dispose of the objects. If you are running the debugging version of the
- // SecretGraphics init with notices set, you will receive a notice that you had not disposed of everything. You
- // can turn notices on in this file by setting gDebugging = TRUE (above).
- //
- GXDisposeShape(gRectangleShape);
- GXDisposeShape(gWindowBoundsShape);
- DisposeWindow(aWindow);
- }
-
-
-
- /*------ DoClick ---------------------------------------------------------------------------------------*/
-
- void DoClick( orgMouseLoc, theWindow )
- gxPoint orgMouseLoc;
- WindowPtr theWindow;
- {
- }
-
-
- /*------ DoIdle ----------------------------------------------------------------------------------------*/
-
- void DoIdle(aWindow)
- WindowPtr aWindow;
- {
- DoDraw(aWindow);
- }
-